#include<stdio.h>
#define STACK_SIZE 100
typedef int ElemType;

typedef struct sharestack
{
	ElemType Elem_array[STACK_SIZE];
	int top[2];//两个栈顶指针
}ShareStack;

int push(int i,ElemType e,ShareStack *S)
{
/*
	规定1为下方的栈，2为上方的栈
	传入的参数，i为栈号，确定传入还是下
*/
	if (i<0||i>1)
		return 2;
	if (S->top[1] - S->top[0] == 1)
	{
		printf("栈满！\n");
		return 2;
	}

	switch(i)
	{
		case 0:S -> Elem_array[++S -> top[0] ] = e; return 1; break;
		case 1:S -> Elem_array[--S -> top[1] ] = e; return 1;
	}

}

ElemType pop(ShareStack *S,int i)//i为栈号
{
	if (i<0||i>1)
	{
		printf("栈号错误\n");
		exit(0);
	}
	
	switch(i)
	{
		case 0:
			if (S -> top[0] == -1)
			{
				printf("栈空\n");
				exit(0);
			}
			else
				return S -> Elem_array[S -> top[0]--];

		case 1:
			if (S -> top[2] == STACK_SIZE)
			{
				printf("栈空\n");
				exit(0)
			}
			else
				return S -> Elem_array[S -> top[1]++];
	}


}